<template>
  <div>
      <div class="product-commend-pic">
        <dl v-for="(product,index) in productList" :key="index" @click="handlerProductDetails(product.product_id)">
          <div class="del-radius-btn" @click.stop="delProduct(product.collection_id)"><i class="iconfont icon-shanchu"></i></div>
          <dt>
            <img :src="product.product_cover+'?x-oss-process=image/resize,w_400,h_400/quality,Q_80/format,jpg'" mode="aspectFit" />
            <div class="Pstate" v-if="product.product_status == 0">下架</div>
          </dt>
          <dd>
            <p class="designerName">{{product.designer_name}}</p>
            <p class="productName">{{product.product_name}}</p>
            <p class="productprice">
              <font class="showPrice">{{product.currency_logo}}{{product.show_price}}</font>
            </p>
          </dd>
        </dl>
      </div>
    <div class="spinnerBox" :hidden="footerHide">
      {{loadMoreText}}
      <div class="spinner" v-if="hasMore">
        <div class="bounce1"></div>
        <div class="bounce2"></div>
        <div class="bounce3"></div>
      </div>
    </div>
    <placeholder :show.sync="isPageEmpty" :message.sync="emptyMsg"  :hidBtn="hidBtn" @tryAgain="onTap" :styleTop="0"/>
  </div>
</template>

<script>
import placeholder from '@/components/placeholder'
import pullmixin from '@/mixins/PullRefreshLayout'
import common from '@/utils/common'

export default {
  data() {
    return {
      productList: [],
      scrollHeight: 0
    }
  },
  mixins: [pullmixin],
  onLoad() {
    this.scrollHeight = common.getWindowHeight()
    this.$wx.setTitleBarTitle('我的收藏')
  },
  methods: {
    onTap(){
      this.onRefresh(true)
    },
    handlerProductDetails(id) {
      this.$wx.jumper('/pages/productDetails/main?productId=' + id)
    },
    async delProduct(id){
      const data = await this.$fly.post(this.$url.URL_DELCOLLECTIONPRODUCTS, {
        collection_id: id
      })
      if (data.successCode === 1) {
        this.onRefresh(true)
      }
    },
    onRefresh(isRefresh) {
      this.getdata(isRefresh)
    },
    async onRefresh(isRefresh) {
      const data = await this.$fly.post(this.$url.URL_COLLECTIONPRODUCTS, {
        page_index: isRefresh
          ? (this.paramsDatas.pageIndex = 1)
          : this.paramsDatas.pageIndex,
        page_size: this.paramsDatas.pageSize
      })
      if (data.successCode) {
        this.preHandler(isRefresh, data.data.products.length)
        if (isRefresh) {
          this.productList = data.data.products
          console.log(this.productList)
          if (data.data.products.length <= 0) {
            this.isPageEmpty = true
            this.emptyMsg = '暂无收藏的商品'
            this.hidBtn = true
          } else {
            this.isPageEmpty = false
          }
        } else {
          this.productList.push.apply(this.productList, data.data.products)
        }
      } else {
        this.handlerFail(isRefresh)
      }
    }
  },
  mounted() {
    this.onRefresh(true)
  },
  components: {
    placeholder
  }
}
</script>

<style scoped>
.product-commend-pic {
  overflow: hidden;
}
.product-commend-pic dl {
  position: relative;
  padding: 2% 3% 1%;
  background-color: #fff;
  box-shadow: 0 2px 6px #e8e8e8;
  width: 48%;
  float: left;
  box-sizing: border-box;
  margin: 4% 1% 0;
}
.product-commend-pic dl .del-radius-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px #eee solid;
  width: 20px;
  height: 20px;
  line-height: 19px;
  text-align: center;
  z-index: 99;
  border-radius: 50%;
}
.product-commend-pic dl dt {
  text-align: center;
  position: relative;
  display: flex;
  display: -webkit-flex;
}
.product-commend-pic dl dt img {
  position: absolute;
  height: 100%;
  width: 100%;
}
.product-commend-pic dl dt span {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  line-height: 40px;
  text-align: center;
  z-index: 9;
}
.product-commend-pic dl dt span .iconfont {
  color: #cbcbcb;
}
.product-commend-pic dl dt span.red .iconfont {
  color: #ff4545;
}
.product-commend-pic dl dt:after {
  content: ' ';
  padding: 50% 0;
  width: 100%;
  display: inline-block;
}
.product-commend-pic dl dd {
  min-height: 86px;
}
</style>
